import { Cascader, Input } from "antd"
import { ActionGroup } from ".."
import FormSelect from "../../../components/cell/FormSelect"
import MyCard from "../../../components/core/MyCard"
import PageForm, { MyFormItemProps } from "../../../components/core/PageForm"
import { custTypesList, maritalStatusList } from "../../../enum"
import useCommonModel from "../../../model/useCommonModel"
import useIntentModel from "../../../model/useIntentModel"
import InputCell from "../cell/inputCell"
import IdCardExpirationDateCell from "../cell/idCardExpirationDateCell"
import { useGetUiState } from "../helper/init"

const CustomerGroup = ({ title, groupkey }: ActionGroup) => {

    const { entryInfo } = useIntentModel()
    const { areaData } = useCommonModel()
    const { isViewMode, isAlterTenantMode, isPreSecondSignMode } = useGetUiState()
    const customer = entryInfo?.customer || {}
    const { custType, custName, idNo, mobile, maritalStatus, provinceCode, cityCode, areaCode } = customer
    const threeConditions = isViewMode || isAlterTenantMode || isPreSecondSignMode
    const twoConditions = isViewMode || isPreSecondSignMode
    const not_c = custType !== 'C'
    const not_m = maritalStatus !== 'M'

    const children: Array<MyFormItemProps> = [
        { label: '业务对象', children: <FormSelect disabled options={custTypesList} value={custType} keyName="CustomerGroup_custType" labelFormat={val => { return `${val}用户` }} /> },
        { label: '客户姓名', children: <Input disabled value={custName} /> },
        { label: '证件号', children: <Input disabled value={idNo} /> },
        { label: '身份证到期日', children: <IdCardExpirationDateCell />, required: true, hidden: not_c },
        { label: '手机号', children: <Input disabled value={mobile} /> },
        { label: '婚姻状况', children: <FormSelect disabled options={maritalStatusList} value={maritalStatus} keyName="CustomerGroup_maritalStatus" /> },
        { label: '通讯省市区', children: <Cascader disabled options={areaData} value={[provinceCode, cityCode, areaCode]} /> },
        { label: '具体地址', children: <InputCell methodkey="updateCustomerInfo" updatekey="postalAddress" disabled={threeConditions} />, required: true },
        { label: '配偶姓名', children: <InputCell methodkey="updateCustomerInfo" updatekey="spouseName" disabled={twoConditions} />, hidden: not_m },
        { label: '配偶证件号', children: <InputCell methodkey="updateCustomerInfo" updatekey="spouseIdNo" disabled={twoConditions} />, hidden: not_m },
        { label: '配偶手机号', children: <InputCell methodkey="updateCustomerInfo" updatekey="spouseMobile" disabled={twoConditions} />, hidden: not_m },
        { label: '配偶户籍地址', children: <InputCell methodkey="updateCustomerInfo" updatekey="spouseAddress" disabled={twoConditions} />, hidden: not_m },
    ]

    return <MyCard groupkey={groupkey} title={title}>
        <PageForm formList={children} loopKey="CustomerGroup" />
    </MyCard >

}

export default CustomerGroup